<?php

namespace App\Http\Controllers\AjaxRequest;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Input;
use Redirect;

class submitcontroller extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  Request  $request
     * @return Response
     */
    public function store(Request $request)
    {
         $I_UserName = $request->input('I_UserName');
         $I_PassW = $request->input('I_PassW');
         $json_arr = array("username"=>$I_UserName,"password"=>$I_PassW,);
       //  $json_obj = json_encode($json_arr);

         $o="";
        foreach ($json_arr as $k=>$v)
       {
            $o.= "$k=".urlencode($v)."&";
        }
            $json_data=substr($o,0,-1);
            $url =  "192.168.0.21:8080/test/user";
            $ch = curl_init();
             curl_setopt($ch,CURLOPT_URL,$url); /*获取URL的内容*/
             //do a post
            curl_setopt($ch,CURLOPT_POST,true);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$json_data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);/*获取的内容不输出*/
            $content = curl_exec($ch);/*输出获取的内容*/
            //  $httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
            curl_close($ch);
             $obj = json_decode($content);
             if (isset($obj->id)){
                    return Redirect::to('register?userid='.$obj->id);
              //      header("Location:/register?userid=".$obj->id);
              //      exit(0);
             }else{
                  return Redirect::back()->withInput()->withErrors('注册失败');
             }
     
            
    //  return response()->json($arrayName = array('result' => $content));
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  Request  $request
     * @param  int  $id
     * @return Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        //
    }
}
